/*
 * @Description: 
 * @Author: Zilu
 * @Date: 2021-11-04 16:13:47
 * @Version: 
 * @LastEditTime: 2021-11-04 16:26:53
 * @LastEditors: Zilu
 */
// wordcnt.c  --统计字符数、单词数和行数
#include <stdio.h>
#include <ctype.h>      //isspace()函数原型
#include <stdbool.h>    //bool别名

#define STOP '|'    // 用'|'字符作为计数输入的标志

int main(void)
{
    char c;     //读入字符
    char prev;  //读入的前一个字符
    long n_chars = 0;
    int n_lines = 0;
    int n_words = 0;
    int p_lines = 0;
    bool inword = false;    //字符c是否在单词中，不使用inword也行

    printf("Please enter text to be analyzed(| to end):\n");
    prev = '\n';
    while ((c=getchar()) != '|')
    {
        n_chars++;
        if (c=='\n')
            n_lines++;
        if (!isspace(c) /* && !inword */){
            // inword = true;
            n_words++;
        }
        if (isspace(c) /* && inword */){
            inword = false;
        }
        prev = c;
    }

    if (prev != '\n')
    {
        p_lines = 1;
    }
    printf("Characters:%ld, words:%d, lines:%d, partial lines:%d \n", n_chars, n_words, n_lines, p_lines);

    return 0;
}